//
// Created by Administrator on 2022/11/20.
//
#include "arrUtil.h"

using namespace std;

vector<int> merge(vector<int> &v, int l, int r, int m)
///
/// \param v 数组
/// \param l 数组左边界
/// \param r 右边界
/// \param m 右边有序的第一个元素的索引
/// \return
{
    vector<int> vv;
    int i=l,j=m;
    while(i<m && j<=r)
    {
        if(v[i]<=v[j])
        {
            vv.push_back(v[i]);
            ++i;
        }else{
            vv.push_back(v[j]);
            ++j;
        }
    }
    for(;i<m;++i) vv.push_back(v[i]);
    for(;j<=r;++j) vv.push_back(v[j]);
    return vv;
}

int main()
{
    vector<int> arr = {0, 2, 3, 8, 1, 4, 5, 7};
    printVector(merge(arr, 0, arr.size() - 1, 4));
    printVector(arr);
    return 0;
}
